//
//  RHDeviceDataSectionView.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/12/8.
//

#import "RHDeviceDataSectionView.h"
@interface RHDeviceDataSectionView ()

@property (nonatomic, strong) UIImageView *arrowImg;

@property (nonatomic, strong) QMUIButton *btn;

@property (nonatomic, strong) QMUILabel *moreLab;

@property (nonatomic, strong) UIView *line;
@end
@implementation RHDeviceDataSectionView

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithReuseIdentifier:reuseIdentifier]){
        [self setupUI];
    }
    return self;
}

-(void)hideArrowView:(BOOL)hidden
{
    self.arrowImg.hidden = hidden;
    self.btn.hidden = hidden;
    self.moreLab.hidden = hidden;
}

-(void)hideLine:(BOOL)hidden
{
    self.line.hidden = hidden;
//    [self.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_offset(hidden?0:15);
//    }];
}

-(void)setupUI
{
    
    kWeakSelf;
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(15, 0, kUI_WINDOW_W-30, 40)];
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 8;
    bgView.layer.maskedCorners = kCALayerMinXMinYCorner|kCALayerMaxXMinYCorner;
    [self addSubview:bgView];
    self.bgView = bgView;
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(15, 15, 0, 15));
    }];
    
    _titleLab = [[QMUILabel alloc]initWithFrame:CGRectMake(15, 15, 300, 20)];
    _titleLab.textColor = kCOLOR_HEX(@"171A1D");
    _titleLab.font = kBOLDSYSTEMFONT(16);
    _titleLab.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:_titleLab];
    [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.top.mas_offset(15);
    }];
    
    _arrowImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"kwt_home_arrow"]];
    [bgView addSubview:_arrowImg];
    
    [_arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(15);
        make.right.mas_offset(-10);
        make.centerY.equalTo(weakSelf.titleLab);
    }];
    
    _moreLab = [[QMUILabel alloc]initWithFrame:CGRectMake(15, 15, 300, 20)];
    _moreLab.textColor = kCOLOR_HEX_A(@"3F4443",0.6);
    _moreLab.text = @"更多".rh_localized;
    _moreLab.font = kBOLDSYSTEMFONT(14);
    _moreLab.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:_moreLab];
    [_moreLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.arrowImg.mas_left).mas_offset(-5);
        make.centerY.equalTo(weakSelf.arrowImg);
    }];
    
    UIView *line = kView;
    line.backgroundColor = kCOLOR_HEX_A(@"#7E868E", 0.16);
    [bgView addSubview:line];
    self.line = line;
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_offset(0);
        make.height.offset(1);
    }];
    
    _btn = [[QMUIButton alloc]init];
    [bgView addSubview:_btn];
    [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    
    [[_btn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.seeMoreBlock){
            weakSelf.seeMoreBlock();
        }
    }];
}

@end
